import pika


# 定义回调函数，用于处理接收到的消息
def callback(ch, method, properties, body):
    print(f" [x] Received '{body.decode()}'")


# 连接到 RabbitMQ 服务器
credentials = pika.PlainCredentials('admin', 'Parav1ew!')  # 替换为你的用户名和密码
parameters = pika.ConnectionParameters('10.10.2.236', 31331, '/', credentials)
connection = pika.BlockingConnection(parameters)
channel = connection.channel()

# 声明队列
queue_name = 'DRS00002'
channel.queue_declare(queue=queue_name, durable=True)

# 设置消费者，指定回调函数
channel.basic_consume(queue=queue_name,
                      on_message_callback=callback,
                      auto_ack=True)  # auto_ack=True 表示自动确认消息

print(' [*] 等待消息. 退出按 CTRL+C')

# 开始监听队列
channel.start_consuming()
